package org.fiel.struts.actions;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import org.apache.log4j.Logger;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

import org.apache.log4j.PropertyConfigurator;
import org.apache.torque.Torque;

import org.fiel.FielConstants;

/**
 * @author Luis Pablo Gallo (luispablo.gallo@gmail.com)
 */
public class TorquePlugin implements PlugIn
{
    private Logger logger = Logger.getLogger(TorquePlugin.class);
    
    public void init(ActionServlet servlet, ModuleConfig config)
    throws ServletException
    {
        try
        {
            String file = FielConstants.TORQUE_PROPERTIES_FILE;
            String prefix = servlet.getServletContext().getRealPath("/WEB-INF/");
            
            Torque.init(prefix +"/"+ file);
            
            this.logger.debug("Se ha configurado Torque exitosamente.");
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            throw new ServletException(ex);
        }
    }
    
    public void destroy()
    {
    }
    
}